package com.upu173.music.service;

import android.app.Service;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;

import com.upu173.music.receiver.PlayerManagerReceiver;

public class MusicPlayerService extends Service {

    public static PlayerManagerReceiver playerManagerReceiver;

    public MusicPlayerService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public void onCreate() {
        super.onCreate();
        register();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        unRegister();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return super.onStartCommand(intent, flags, startId);
    }


    private void register() {
        playerManagerReceiver = new PlayerManagerReceiver(MusicPlayerService.this);
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(PlayerManagerReceiver.ACTION_MUSIC_PLAYER);
        registerReceiver(playerManagerReceiver, intentFilter);
    }

    private void unRegister() {
        if (playerManagerReceiver != null) {
            unregisterReceiver(playerManagerReceiver);
        }
    }

}

